﻿////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// <copyright>Copyright 2008-2011 Andreas Huber Doenni</copyright>
// Distributed under the Microsoft Public License (Ms-PL).
// See accompanying file License.txt or copy at http://mews.codeplex.com/license.
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

namespace Mews.Net.Nntp
{
    using System;

    /// <summary>Represents a LISTGROUP command to be sent to an NNTP server, see
    /// <a href="http://www.ietf.org/rfc/rfc3977.txt">RFC 3977</a> 6.1.2.</summary>
    /// <remarks>Some NNTP servers (e.g. news.microsoft.com) only implement the older variant (see
    /// <a href="http://tools.ietf.org/rfc/rfc2980.txt">RFC 2980</a>) of this command and therefore do not pass the
    /// initial response line arguments required by the current standard. To ensure maximum interoperability,
    /// no attempt is made to parse these arguments. Client code requiring this information can obtain it by sending a
    /// <see cref="GroupCommand"/> beforehand.</remarks>
    /// <threadsafety static="true" instance="false"/>
    public sealed class ListGroupCommand : SingleLineCommand<ListGroupResponse>
    {
        private static readonly string[] successResponseCodes = { "211" };

        /// <summary>Initializes a new instance of the <see cref="ListGroupCommand"/> class.</summary>
        public ListGroupCommand() : this(null, null)
        {
        }

        /// <summary>Initializes a new instance of the <see cref="ListGroupCommand"/> class.</summary>
        /// <exception cref="ArgumentNullException"><paramref name="name"/> equals <c>null</c>.</exception>
        /// <exception cref="ArgumentException"><paramref name="name"/> contains white space.</exception>
        public ListGroupCommand(string name) : this(" ", name)
        {
            CommandHelper.AssertContainsNoWhiteSpace("name", name);
        }

        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////

        /// <summary>See <see cref="SingleLineCommandBase{T, U}.CreateResponse"/>.</summary>
        protected sealed override ListGroupResponse CreateResponse(ResponseStream responseStream)
        {
            return new ListGroupResponse(responseStream);
        }

        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////

        private ListGroupCommand(string separator, string arguments) :
            base("LISTGROUP" + separator + arguments, 2, successResponseCodes)
        {
        }
    }
}
